package com.nuanshui.heatedloan.userinfo.model;

import java.util.Date;
import java.util.concurrent.ConcurrentHashMap;

import com.alibaba.fastjson.annotation.JSONField;
import com.nuanshui.framework.lang.DateUtil;
import com.nuanshui.heatedloan.dal.BaseEntityImpl;

public class IntegralAction extends BaseEntityImpl {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String name;//名称
	private String des;//描述
	private Integer numOfDay;//一天可以几次加分 
	private Double score;//分数
	private String actionCode;//编码
	@JSONField(serialize=false)
	private  Date createdAt;//创建时间
	@JSONField(serialize=false)
	private Integer type;//类型
	private String actionLogo;
	private String alertMsg;
	private String skipType;
	private String packageName;//android activity 名
	private  ConcurrentHashMap<String,Integer> surplusNums = new ConcurrentHashMap<String, Integer>();//剩余次数
	
	
	public String getPackageName() {
		return packageName;
	}

	public void setPackageName(String packageName) {
		this.packageName = packageName;
	}

	public String getSkipType() {
		return skipType;
	}

	public void setSkipType(String skipType) {
		this.skipType = skipType;
	}

	public String getAlertMsg() {
		return alertMsg;
	}

	public void setAlertMsg(String alertMsg) {
		this.alertMsg = alertMsg;
	}

	public String getActionLogo() {
		return actionLogo;
	}

	public void setActionLogo(String actionLogo) {
		this.actionLogo = actionLogo;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public ConcurrentHashMap<String, Integer> getSurplusNums() {
		return surplusNums;
	}

	public void setSurplusNums(ConcurrentHashMap<String, Integer> surplusNums) {
		this.surplusNums = surplusNums;
	}
	
   public boolean isAlertMsg(String userId) {
	   if(getNumOfDay() == -1) return true;
	   String day = DateUtil.getToday("yyyy-MM-dd");
	   String key = day+"_"+userId;
	   Integer  surplusNum = surplusNums.get(key);
	   if(surplusNum == null) return true;
	   return false;
   }

	public boolean isIncr(String userId) {
		if(getNumOfDay() == -1) return true;
		String day = DateUtil.getToday("yyyy-MM-dd");
		String key = day+"_"+userId;
		Integer  surplusNum = surplusNums.get(key);
		if(surplusNum == null) {//表示第一次
			surplusNums.put(key,getNumOfDay()-1);
			return getNumOfDay()>0;
		}
		surplusNums.put(key,surplusNum-1);
		return surplusNum>0;
	}
	/**
	 * 判断是否还可以加分
	 * @param userId
	 * @return
	 */
	public boolean isNotIncr(String userId) {
		if(getNumOfDay() == -1) return false;
		String day = DateUtil.getToday("yyyy-MM-dd");
		String key = day+"_"+userId;
		Integer  surplusNum = surplusNums.get(key);
		if(surplusNum == null) {//表示第一次
			return getNumOfDay()<=0;
		}
		return surplusNum<=0;
	}
	@Override
	public Date getCreatedAt() {
		return createdAt;
	}
	@Override
	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDes() {
		return des;
	}
	public void setDes(String des) {
		this.des = des;
	}
	public Integer getNumOfDay() {
		if(numOfDay == null) return 0;
		return numOfDay;
	}
	public void setNumOfDay(Integer numOfDay) {
		if(numOfDay == null) {
			numOfDay = 0;
			return;
		}
		this.numOfDay = numOfDay;
	}
	public Double getScore() {
		return score;
	}
	public void setScore(Double score) {
		this.score = score;
	}
	public String getActionCode() {
		return actionCode;
	}
	public void setActionCode(String actionCode) {
		this.actionCode = actionCode;
	}

}
